import { Injectable } from '@angular/core';
import {FrameContext,BindingData,Repository} from '@farris/devkit';
@Injectable()
export class SbssTsjlFrmControllerService {
  constructor(
            private frameContext:FrameContext,
  ) {}

  /**
   * 组件初始化事件
   * @remarks 
   * @returns 
   */
  componentOnInit(): any {
    this.initSubFilter()
  }


  /**
   * 初始化子表筛选
   */
  initSubFilter():any{
    /** 
    let compmentName = 'sbssTsjlSub-92g9-component_sbsstsjlsub_root-component';       
    let component = this.frameContext.appContext.frameContextManager.getFrameContextById(compmentName)
    */
    const defaultValue = {
            fieldConfigs: [
                {
                    labelCode: "rq",
                    value: {
                        startTime: this.getCurrentDate(1),
                        endTime: this.getCurrentDate()
                    }
                },
            ]}

    this.frameContext.uiState['subFilterConitionList'] = defaultValue
  }

    private getCurrentDate(getFd = 0) {
    const today = new Date();
    const year = today.getFullYear();
    const month = this.padLeft(String(today.getMonth() + 1),2); // 月份从0开始，需要+1
    const day =  this.padLeft(String(today.getDate()),2);
    
    if ( getFd == 0){
      return `${year}-${month}-${day}`;
    }
    return `${year}-${month}-01`;
  }

  private padLeft(str, length, char = '0') {
    str = String(str);
    return (Array(length + 1).join(char) + str).slice(-length);
  }
}
